Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][OpenMP] Handle expressions in target ... do loop control #107

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

ergawy
Copy link

@ergawy ergawy commented Jul 3, 2024

When emitting the ops required to compute the target loop's trip count, flang might emit ops outside the target regions that operands defined inside the region. This is fixed up by HostClausesInsertionGuard already.

However, the current support only handles simple cases. If the loop control contains more elaborate expressions, the fix up logic does not handle it properly. This PR handles such cases.

When emitting the ops required to compute the target loop's trip count,
flang might emit ops outside the target regions that operands defined
inside the region. This is fixed up by `HostClausesInsertionGuard`
already.

However, the current support only handles simple cases. If the loop
control contains more elaborate expressions, the fix up logic does not
handle it properly. This PR handles such cases.
Copy link

@skatrak skatrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Kareem for this work. It looks like it should do the trick, I just have a couple of nits and some suggestions to try improve it a bit before merging.

flang/lib/Lower/OpenMP/OpenMP.cpp Show resolved Hide resolved
flang/lib/Lower/OpenMP/OpenMP.cpp Outdated Show resolved Hide resolved
flang/lib/Lower/OpenMP/OpenMP.cpp Outdated Show resolved Hide resolved
operand->getOwner()->setOperand(operand->getOperandNumber(),
lastSliceOp->getResult(operandResultIdx));
}

auto useOutsideTargetRegion = [](mlir::OpOperand &operand) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm wondering: Is everything from here to the end of the function needed still? It seems like your additions may potentially be already handling all cases. You can try commenting it out and running check-flang and smoke-fort tests and see what happens.

Copy link
Author

@ergawy ergawy Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything from this point below is still needed. What I added perpares for the following logic to work properly in case a target region argument is used indirectly outside the region. What I added above does not remap the target region arguments.

This is verifiable even using the lit test I added below. If you comment out the logic you previously added, you will find that now we clone the slice of operations needed by the trip count calculation but at the root of this slice, a use of the target region argument is still there.

flang/lib/Lower/OpenMP/OpenMP.cpp Outdated Show resolved Hide resolved
Copy link

@agozillon agozillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I believe @skatrak covered everything with his comments! So please address them and wait on his approval prior to merging.

I have one likely stupid question though, as I am a little naive with this segment of work, would this create additional unused omp.map.info operations as we previously had the defining operation inside of the target region and then lifted it out? I would imagine not, and the inverse is more likely. But I thought it was worth clarifying my understanding of the interaction as we have a segment of code that will clone the use chain into the target region if it can, but if it can't it'll generate map operations. However, this is sort of the inverse situation in a way.

TL;DR: there's two ways we generate map.info operations implicitly, I am wondering if we end up generating map.info in this situation that we no longer require after this modification is performed!

@ergawy
Copy link
Author

ergawy commented Jul 4, 2024

... would this create additional unused omp.map.info operations as we previously had the defining operation inside of the target region and then lifted it out? ...

Not a stupid question at all 😛!

We do not create any additional omp.map.info ops since we do not actually lift the defining op but clone it (along with the slice of ops that define its operands) and then after cloning we remap the operands of the cloned slice to use values defined outside the target region.

@agozillon
Copy link

... would this create additional unused omp.map.info operations as we previously had the defining operation inside of the target region and then lifted it out? ...

Not a stupid question at all 😛!

We do not create any additional omp.map.info ops since we do not actually lift the defining op but clone it (along with the slice of ops that define its operands) and then after cloning we remap the operands of the cloned slice to use values defined outside the target region.

Thank you for explaining that and clarifying it for me!

Copy link

@skatrak skatrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Kareem for your clarifications, LGTM!

@ergawy ergawy merged commit 6bd0a22 into ROCm:amd-trunk-dev Jul 4, 2024
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants